<template>
  <el-container>
    <el-header style="height:80px;">
      <el-form
        ref="form"
        label-width="80px"
        style="margin-top:20px;"
      >
        <el-row>
          <el-col :span="16">
            <el-form-item label="创建时间:">
              <el-col :span="10">
                <el-date-picker
                  v-model="startDate"
                  type="datetime"
                  placeholder="日期选择框"
                  :editable="false"
                >
                </el-date-picker>
              </el-col>
              <el-col
                class="line"
                :span="2"
                style="text-align: center"
              >-</el-col>
              <el-col :span="10">
                <el-date-picker
                  v-model="endDate"
                  type="datetime"
                  placeholder="日期选择框"
                  :editable="false"
                >
                </el-date-picker>
              </el-col>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label-width="0">
              <el-button
                @click="query(search)"
                type="primary"
              >查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-header>
    <el-main>
      <section class="contant_head">
        <span>图表
          <!-- <sub>Form</sub> -->
        </span>
      </section>
      <el-table
        :data="tableData"
        border
        style="width: 98%;margin:10px;text-align:center;"
        :header-cell-style="getRowClass"
      >
        <el-table-column
          prop="cNickname"
          label="操作人姓名"
          height="200px"
        > </el-table-column>
        <el-table-column
          prop="cOperatorModule"
          label="操作类型"
        ></el-table-column>
        <el-table-column
          prop="cIp"
          label="登录IP"
        > </el-table-column>
        <el-table-column
          prop="cOperatorFunction"
          label="操作说明"
        ></el-table-column>
        <el-table-column
          prop="cOperatorTime"
          label="操作时间"
        ></el-table-column>
        <!-- <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" size="medium">查看详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next"
          :total="total"
          style="float:right"
        >
        </el-pagination>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import { api } from "@/fetch/api";


export default {
  data() {
    return {
      search: {
        createTime: "",
      },
      limit: 10,
      currentPage: 1,
      total: null,
      sysLog: {
        cIp: "",
        cLogId: 0,
        cNickname: "",
        cOperatorFunction: "",
        cOperatorModule: "",
        cOperatorTime: "",
        cUserId: 0,
        cUsername: "",
        endDate: "",
        remark: "",
        limit: 0,
        startDate: ""
      },
      endDate: '',
      startDate: '',
      currentPage: 1,
      total: null,
      tableData: []
    };
  },
  methods: {
    getPermission() {
      api
        .PermissionPage({}, { limit: 0, pageIndex: 0 })
        .then(response => {
          if (response.status === 100) {
            this.permissions = response.result.list;
            api.LocalStorageService.update("permissions", response.result.list);
          } else {
          }
        })
        .catch(error => { });
    },
    getRole() {
      api
        .RolePage({}, { limit: 0, pageIndex: 0 })
        .then(response => {
          if (response.status === 100) {
            this.role = response.result.list;
            api.LocalStorageService.update("role", response.result.list);
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    getUser(limit, pageIndex) {
      this.search.endDate = this.endDate
        ? new Date(this.endDate)
        : null;
      this.search.startDate = this.startDate
        ? new Date(this.startDate)
        : null;
      api.LogPage(this.search, { limit: 10, pageIndex: pageIndex }).then(response => {
        if (response.status === 100) {
          this.tableData = response.result.list;
          this.tableData.forEach(function (item, index) {
            item.index = index + 1 + (pageIndex - 1) * limit;
          });
          this.total = response.result.total;
        } else {
          this.$message.error(response.message);
        }
      });
    },
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex == 0) {
        return "background:rgba(242,242,242,1)";
      } else {
        return "";
      }
    },
    query(search) {
      search.endDate = this.endDate
        ? new Date(this.endDate)
        : null;
      search.startDate = this.startDate
        ? new Date(this.startDate)
        : null;
      api.LogPage(search, { limit: 10, pageIndex: 1 }).then(response => {
        if (response.status === 100) {
          this.tableData = response.result.list;
          this.currentPage = 1;
          this.tableData.forEach(function (item, index) {
            item.index = index + 1;
          });
          this.total = response.result.total;
        } else {
        }
      });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getUser(this.limit, val);
    },
    handleSizeChange(val) {
      this.limit = val;
      this.getUser(val, this.currentPage);
    },
    handleDelete(index, row) {
      this.$confirm("是否继续删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api
            .DeleteUser({
              cUserId: row.cUserId
            })
            .then(response => {
              if (response.status === 100) {
                this.$message.success(response.message);
                this.getUser(this.limit, this.currentPage);
              } else {
              }
            });
        })
        .catch(() => { });
    }
  },
  mounted() {
    this.getPermission();
    this.getRole();
    this.getUser(10, this.currentPage);
    // this.query(this.search);
  }
};
</script>

<style lang="less" scoped>
@import url("../../assets/css/index.css");
.el-header {
  width: 98%;
  background: #fff;
  margin: 0 auto;
  margin-top: 20px;
  margin-bottom: 20px;
  .el-input,
  .el-select,
  .el-date-picker {
    width: 100%;
  }
}
.el-main {
  width: 98%;
  background: #fff;
  margin: 0 auto;
  padding: 0px;
  .contant_head {
    border-left: 3px solid #f7585d;
    background: #f9f9f9;
    height: 40px;
    span {
      line-height: 40px;
      font-size: 20px;
      padding-left: 10px;
      sub {
        font-size: 12px;
      }
    }
  }
}
.el-checkbox {
  margin-right: 12%;
  font-size: 20px;
  color: #4a4a4a;
}
</style>
<style>
.cell {
  text-align: center;
}
</style>


